<template>
  <div class="dialog" v-show="isShow">
    <!-- <transition name="fade" mode="out-in"> -->
      <div class="mask" :style="{ opacity: op }">
        <div class="box" :style="{ transform: `translateY(${top}px)` }">
          <div class="close" @click="close">x</div>
          <slot>
            <!-- 使用时插入具体内容 -->
          </slot>
        </div>
      </div>
    <!-- </transition> -->
  </div>
</template>

<script>
export default {
  name: 'BookstoreDialog',
  data() {
    return {
      isShow: false,
      top: 0,
      op: 0
    };
  },

  mounted() {
    var that = this;
    this.$bus.$on("showDialog", function (e) {

      if (e) {
        that.isShow = true;
        setTimeout(() => {
          that.top = 0;
          that.op = 1;
        }, 300);
      }

    });
  },

  methods: {
    close() {
      this.isShow = false;
      setTimeout(() => {
        this.top = -500;
        this.op = 0;
      }, 300);
    }
  },
};
</script>

<style scoped>
.dialog {
  position: fixed;
  top: 0px;
  left: 0px;
  width: 100vw;
  height: 100vh;
}

.mask {
  width: 100%;
  height: 100%;
  background-color: rgba(00, 00, 00, .5);
  padding-top: 200px;
}

.box {
  width: 800px;
  height: 300px;
  margin: 0px auto;
  background-color: #ffffff;
  position: relative;
}

.close {
  display: block;
  cursor: pointer;
  position: absolute;
  top: 5px;
  right: 15px;
}


.fade-enter {
  transform: translateY(-500px);
}

.fade-leave-to {
  transform: translateY(-500px);
}

.box {
  transition: all .5s;
}

.fade-enter-active {
  transition: all .5s;
}

.fade-leave-active {
  transition: all .5s;
}
</style>
